<template>
  <div class="app-container">
    <Search-content :queryParams="queryParams" labelWidth="145px" @query="handleQuery" @reset="resetQuery">
      <el-col :span="6">
        <el-form-item label="车牌号/车架号:">
          <el-input v-model="queryParams.carNoVinNo" clearable placeholder="请输入车牌号/车架号"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="品牌/车系/车型:">
          <linkage-select @changeNode="linkageChange" v-model="linkageList" placeholder="请选择品牌/车系/车型"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="理赔类别:">
          <el-select v-model="queryParams.settlementType" placeholder="请选择车辆状态">
            <el-option label="实物赔付申请" value="1"/>
            <el-option label="理赔款支付申请" value="2"/>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="车辆产权:">
          <el-select filterable v-model="queryParams.propertyRightId" clearable placeholder="请选择车辆产权"
                     style="width: 100%">

            <el-option v-for="item in companyOriginList" :label="item.deptName" :value="item.deptId"
                       :key="item.deptId" />

          </el-select>
        </el-form-item>
      </el-col>
    </Search-content>

    <div class="card-wrap card-padding">
      <div class="table-title-wrap justify-end">
        <el-button size="mini" v-hasPermi="['bxlp:settlementList:add']" @click="handleAdd" type="primary">新增
        </el-button>
        <el-button size="mini" v-hasPermi="['bxlp:settlementList:derive']" @click="handleExport" type="primary">导出
        </el-button>
      </div>

      <table-page :loading="loading" :dataList="dataList" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @setSizeCurrent="handleList" border>
        <template slot="tableColAc">
          <el-table-column label="操作" align="center" fixed="left" width="100">
            <template #default="{ row }">
              <el-button size="mini" type="text" @click="handleView(row)"
                         v-hasPermi="['bxlp:settlementList:view']">查看
              </el-button>

              <el-button size="mini" type="text" v-hasPermi="['bxlp:settlementList:dele']"
                         v-if="['理赔款支付-已完成','实物赔付-已完成'].includes(row.settlementStatus)"
                         @click="handleDelete(row)">删除
              </el-button>
            </template>
          </el-table-column>
        </template>

        <template slot="tableCol">
          <el-table-column align="center" label="车牌号" min-width="100">
            <template #default="{ row }">
              <el-button class="enable-text-select" type="text">{{ row.carNo }}</el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" label="车架号" min-width="180" show-overflow-tooltip prop="vinNo"/>

          <el-table-column align="center" label="品牌/车系/车型" show-overflow-tooltip min-width="320">
            <template #default="{ row }">
              {{ row.brandName }}{{
                row.seriesName ? "/" + row.seriesName : ""
              }}{{ row.modelName ? "/" + row.modelName : "" }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="车辆产权" show-overflow-tooltip min-width="120"
                           prop="propertyRightName"/>

          <el-table-column align="center" label="出险日期" show-overflow-tooltip min-width="120" prop="accidentTime"/>

          <el-table-column align="center" label="商业险保单号" show-overflow-tooltip min-width="120"
                           prop="compulsoryPolicyNum"/>

          <el-table-column align="center" label="交强险保单号" show-overflow-tooltip min-width="120"
                           prop="commercialPolicyNum"/>

          <el-table-column align="center" label="理赔状态" show-overflow-tooltip min-width="180" prop="settlementStatus" />

          <el-table-column align="center" label="理赔类别" show-overflow-tooltip min-width="120">
            <template #default="{row}">
              <span v-if="row.settlementType === '1'">实物赔付申请</span>
              <span v-if="row.settlementType === '2'">理赔款支付申请</span>
            </template>
          </el-table-column>

          <el-table-column align="center" label="主车定损损金额" show-overflow-tooltip min-width="140"
                           prop="vehicleAssessmentPrice"/>

          <el-table-column align="center" label="主车定损-人伤金额" show-overflow-tooltip min-width="160"
                           prop="persionAssessmentPrice"/>

          <el-table-column align="center" label="主车定损-其他" show-overflow-tooltip min-width="140"
                           prop="otherAssessmentPrice"/>

          <el-table-column align="center" label="定损总计" show-overflow-tooltip min-width="140"
                           prop="otherAssessmentPrice"/>

          <el-table-column align="center" label="签约维修厂/维修厂" show-overflow-tooltip min-width="160"
                           prop="maintenanceShop"/>

        </template>
      </table-page>
    </div>

    <add-car-dialog ref="refAddCarDialog"/>
  </div>
</template>

<script>
import LinkageSelect from "../../components/linkageSelect";
import SearchContent from "@/components/SearchContent/index.vue";
import {getSettlementList, delSettlementList} from "@/api/bxlp/settlement.js"
import addCarDialog from './components/addCarDialog.vue'
import { listDept } from "@/api/system/dept";
export default {
  name: "SettlementList", //保险理赔
  components: {
    LinkageSelect,
    SearchContent,
    addCarDialog
  },
  computed: {},
  watch: {},
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carNoVinNo: '',
        settlementType: '',
        brandName: '',
        seriesName: '',
        modelName: '',
        propertyRightId:'',

      },
      dataList: [],
      total: 0,
      loading: false,
      linkageList: [],
      companyOriginList:[]
    };
  },
  created() {
    this.handleList()
    this.getCompanyOrigin()
  },
  mounted() {
  },
  methods: {
    getCompanyOrigin() {
      listDept({
        deptType: "2", //组织类型（1部门 2公司）
        regionId: null, //所在城市（省市区id）
      }).then((res) => {
        this.companyOriginList = res.data;
      });
    },

    //新增
    handleAdd() {
      this.$refs.refAddCarDialog.handleOpen()
    },

    handleExport() {
      this.download(
          "/car/CarSettlement/export",
          {...this.queryParams},
          `保险理赔列表_${new Date().getTime()}.xlsx`
      )
    },

    handleView(row) {
      this.$router.push({
        name: "SettlementDetails",
        query: {
          id: row.maintenanceId,
          type: 'view'
        }
      });
    },

    handleDelete(row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delSettlementList(row.maintenanceId).then(res => {
          if (res.code === 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.handleList()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },

    linkageChange(val) {
      this.linkageList = val;
      if (val) {
        this.queryParams.brandName = val[0] ? val[0].name : "";
        this.queryParams.seriesName = val[1] ? val[1].name : "";
        this.queryParams.modelName = val[2] ? val[2].name : "";
      } else {
        this.queryParams.brandName = "";
        this.queryParams.seriesName = "";
        this.queryParams.modelName = "";
      }
      this.$forceUpdate();
    },

    handleQuery() {
      this.queryParams.pageNum = 1;
      this.handleList()
    },

    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        carNoVinNo: '',
        settlementType: '',
        brandName: '',
        seriesName: '',
        modelName: '',
        propertyRightId:'',
      }
      this.linkageList = []
      this.handleList()
    },

    async handleList() {
      this.loading = true
      try {
        const res = await getSettlementList(this.queryParams)
        if (res.code === 200) {
          this.total = res.total
          this.dataList = res.rows
        }
      } catch (e) {
        console.error('获取信息失败', e)
      } finally {
        this.loading = false
      }
    }

  },
};
</script>

<style scoped lang=""></style>


